<?php
# Part of RAMS unittest fixtures: totals resource.
# Copyright (C) 2010 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class RamsTotalsTest extends UnitTestCase {
    function TestRamsClientlib() {
        $this->UnitTestCase("Rams Totals Tests");
    }

    function testGetAllTotals() {
      $entriesFound = 0;
      $first_page_all_entry = null;
      $second_page_all_entry = null;
      try {
        $rams = new Rams(NORMAL_USER, NORMAL_PWD, BASE);
        # Pass a Query-String to limit the feed elements to files only
        $query = new Rams_TotalQuery();
        $query->setYear("2010");
        $query->setMonth("9");
        // $query->setType("rtmp");
        # get the feed
        $feed = $rams->getTotalFeed($query);
        foreach ($feed as $entry) {
          switch ($entry->type) {
            case "smooth_live":
              $entriesFound++;
              $this->assertEqual($entry->content->params->unique->text, 1);
              $this->assertEqual($entry->content->params->hits->text, 4);
              $this->assertEqual($entry->content->params->events->text, 40);
              $this->assertEqual($entry->content->params->volume->text, 0.010176731274);
              $this->assertEqual($entry->content->params->last_modified->text, "2010-10-12 13:29:28");
              break;
            case "rats":
              $this->assertEqual($entry->content->params->unique->text, 2);
              $this->assertEqual($entry->content->params->hits->text, 6462);
              $this->assertEqual($entry->content->params->events->text, 6462);
              $this->assertEqual($entry->content->params->volume->text, 0.002184862271);
              $this->assertEqual($entry->content->params->last_modified->text, "2010-10-12 13:32:27");
              $entriesFound++;
              break;
            case "http":
              $this->assertEqual($entry->content->params->unique->text, 135);
              $this->assertEqual($entry->content->params->hits->text, 430);
              $this->assertEqual($entry->content->params->events->text, 430);
              $this->assertEqual($entry->content->params->volume->text, 0.103672521189);
              $this->assertEqual($entry->content->params->last_modified->text, "2010-10-12 13:33:16");
              $entriesFound++;
              break;
            case "rtmp":
              $this->assertEqual($entry->content->params->unique->text, 37);
              $this->assertEqual($entry->content->params->hits->text, 686);
              $this->assertEqual($entry->content->params->events->text, 686);
              $this->assertEqual($entry->content->params->volume->text, 0.230814988725);
              $this->assertEqual($entry->content->params->last_modified->text, "2010-10-12 13:36:12");
              $entriesFound++;
              break;
            case "rass":
              $this->assertEqual($entry->content->params->unique->text, 3);
              $this->assertEqual($entry->content->params->hits->text, 2852);
              $this->assertEqual($entry->content->params->events->text, 2852);
              $this->assertEqual($entry->content->params->volume->text, 0.001541659236);
              $this->assertEqual($entry->content->params->last_modified->text, "2010-10-12 13:39:08");
              $entriesFound++;
              break;
            case "ftp":
              $this->assertEqual($entry->content->params->unique->text, 1);
              $this->assertEqual($entry->content->params->hits->text, 7);
              $this->assertEqual($entry->content->params->events->text, 7);
              $this->assertEqual($entry->content->params->volume->text, 0.004994774237);
              $this->assertEqual($entry->content->params->last_modified->text, "2010-10-12 13:40:59");
              $entriesFound++;
              break;
            case "rtmp_live":
              $this->assertEqual($entry->content->params->unique->text, 1);
              $this->assertEqual($entry->content->params->hits->text, 13);
              $this->assertEqual($entry->content->params->events->text, 142);
              $this->assertEqual($entry->content->params->volume->text, 0.341588024050);
              $this->assertEqual($entry->content->params->last_modified->text, "2010-10-12 13:41:27");
              $entriesFound++;
              break;
            default:
              $this->assertEqual("?", $entry->content->params->name->text);
              break;
          }
        }
        $this->assertEqual($entriesFound, 7); # http + ftp for every file
      }
      catch(Zend_Gdata_App_Exception $e) {
        $this->assertEqual("ok", $e->getResponse()->getBody());
      }
    }
    

}
